<?xml version="1.0" encoding="utf-8"?>
<xs:schema 
  xmlns:tns="http://schemas.ScrumForTeamSystem.com/AggregationService/RulesCollection" 
  elementFormDefault="qualified" 
  targetNamespace="http://schemas.ScrumForTeamSystem.com/AggregationService/RulesCollection" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  >
  <xs:element name="ArrayOfAggregateRule" nillable="true" type="tns:ArrayOfAggregateRule" />
  <xs:complexType name="ArrayOfAggregateRule">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="AggregateRule" nillable="true" type="tns:AggregateRule" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="AggregateRule">
    <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="1" name="WorkItemType" type="tns:SourceTargetPair" />
      <!-- Must have one of the following -->
      <xs:element minOccurs="0" maxOccurs="1" name="Link" type="tns:WorkItemLink" />
      <xs:element minOccurs="0" maxOccurs="1" name="InferredLink" type="tns:InferredLink" />
      <!-- Must have ends -->
      <xs:element minOccurs="1" maxOccurs="1" name="Field" type="tns:SourceTargetPair" />
      <xs:element minOccurs="1" maxOccurs="1" name="ChangeNote" type="xs:string" />
      <xs:element minOccurs="1" maxOccurs="1" name="ExcludedSourceStates" type="tns:ArrayOfString" />
    </xs:sequence>
    <xs:attribute name="type" type="tns:AggregationType" use="required" />
  </xs:complexType>
  <xs:complexType name="SourceTargetPair">
    <xs:attribute name="source" type="xs:string" use="required" />
    <xs:attribute name="target" type="xs:string" use="required" />
  </xs:complexType>
  <xs:complexType name="WorkItemLink">
    <xs:attribute name="linktypename" type="xs:string" use="required" />
    <xs:attribute name="isforward" type="xs:boolean" use="required" />
  </xs:complexType>
  <xs:complexType name="InferredLink">
    <xs:attribute name="depth" type="xs:int" use="optional" />
    <xs:attribute name="type" type="tns:PathMatch" use="required" />
    <xs:attribute name="path" type="tns:LinkPath" use="required" />
  </xs:complexType>
  <xs:simpleType name="PathMatch">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Partial" />
      <xs:enumeration value="Complete" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="LinkPath">
    <xs:restriction base="xs:string">
      <xs:enumeration value="IterationPath" />
      <xs:enumeration value="AreaPath" />
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="ArrayOfString">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="State" nillable="true" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
  <xs:simpleType name="AggregationType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Sum" />
      <xs:enumeration value="Min" />
      <xs:enumeration value="Max" />
      <xs:enumeration value="Average" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>